package code.google.gui.adapter.util;

import java.util.Locale;

import android.app.Activity;
import android.content.Context;
import android.content.res.Resources;
import android.support.v4.app.Fragment;
import code.google.gui.fragments.DummyFragment;
import code.google.gui.fragments.player.PlayerFragment;
import code.google.gui.fragments.player.UpnpFragment;

import com.example.metamusicgui.R;

public class PlayerContext extends MenuContext {
	
	private PlayerFragment player;
	private Fragment playlists;
	private UpnpFragment upnpDeviceList;
	private int itemIDPlayer;
	private int itemIDPlaylist;
	private int itemIDupnpDeviceList;

	public PlayerContext(Context context) {
		super(context);
		
		player = new PlayerFragment();
		playlists = new DummyFragment();
		upnpDeviceList = new UpnpFragment();
		
		itemIDPlayer = getItemID();
		itemIDPlaylist = getItemID();
		itemIDupnpDeviceList = getItemID();
		setDummyData(playlists, "PLAYLISTS");
	}

	@Override
	public Fragment getItemHook(int position) {
		switch (position) {
		case 1:
			return player;
		case 2:
			return playlists;
		case 3:
			return upnpDeviceList;
		default:
			return null;
		}
	}

	@Override
	public int getCountHook() {
		return 3;
	}

	@Override
	public CharSequence getPageTitleHook(int position) {
		Locale l = Locale.getDefault();
		Resources res = context.getResources();
		switch (position) {
		case 1:
			return res.getString(R.string.title_player).toUpperCase(l);
		case 2:
			return res.getString(R.string.title_playlist).toUpperCase(l);
		case 3:
			return res.getString(R.string.title_upnpList).toUpperCase(l);
		}
		return null;
	}

	@Override
	public long getItemIDHook(int position) {
		switch (position) {
		case 1:
			return itemIDPlayer;
		case 2:
			return itemIDPlaylist;
		case 3:
			return itemIDupnpDeviceList;
		}
		return -1;
	}

	@Override
	protected void onRegistrateFragmentsHook(Activity context) {
		
		player.registrateFragmentAt(context);
		upnpDeviceList.registrateFragmentAt(context);
	}

	@Override
	protected void onDeregistrateFragmentsHook(Activity context) {
		player.deregistrateFragmentFrom(context);	
		upnpDeviceList.deregistrateFragmentFrom(context);
	}


}
